/*
Copyright 2014, KISSY v1.47
MIT Licensed
build time: May 22 12:28
*/
KISSY.add("event/dom/touch/handle-map",[],function(){return{}});KISSY.add("event/dom/touch/single-touch",[],function(f){function a(){}a.prototype={constructor:a,requiredTouchCount:1,onTouchStart:function(f){if(f.touches.length!==this.requiredTouchCount)return!1;f=this.lastTouches=f.touches;this.lastXY={pageX:f[0].pageX,pageY:f[0].pageY}},onTouchMove:f.noop,onTouchEnd:f.noop};return a});
KISSY.add("event/dom/touch/tap",["./handle-map","event/dom/base","./single-touch"],function(f,a){function k(e){e.preventDefault()}function h(){h.superclass.constructor.apply(this,arguments)}var c=a("./handle-map"),l=a("event/dom/base"),i=a("./single-touch"),m=l.Object;f.extend(h,i,{onTouchStart:function(e){var b=this;if(!1===h.superclass.onTouchStart.call(b,e))return!1;b.tapHoldTimer&&clearTimeout(b.tapHoldTimer);b.tapHoldTimer=setTimeout(function(){var g=f.mix({touch:e.touches[0],which:1,TAP_HOLD_DELAY:(f.now()-
e.timeStamp)/1E3},b.lastXY);b.tapHoldTimer=0;b.lastXY=0;l.fire(e.target,"tapHold",g)},1E3);b.startTime=e.timeStamp;b.singleTapTimer&&(clearTimeout(b.singleTapTimer),b.singleTapTimer=0)},onTouchMove:function(e){var b;if(!(b=this.lastXY))return!1;e=e.changedTouches[0];if(!e||5<Math.abs(e.pageX-b.pageX)||5<Math.abs(e.pageY-b.pageY))return!1},onTouchEnd:function(e){var b;if(b=this.lastXY){var g=e.target,c=e.changedTouches[0];this.tapHoldTimer&&(clearTimeout(this.tapHoldTimer),this.tapHoldTimer=0);var a=
new m(e.originalEvent);f.mix(a,{type:"tap",which:1,pageX:b.pageX,pageY:b.pageY,target:g,currentTarget:g});a.touch=c;l.fire(g,"tap",a);if(a.isDefaultPrevented()&&f.UA.mobile)if(f.UA.ios)e.preventDefault();else l.on(g.ownerDocument||g,"click",{fn:k,once:1});var a=this.lastEndTime,e=e.timeStamp,j;this.lastEndTime=e;if(a&&(j=e-a,300>j)){this.lastEndTime=0;l.fire(g,"doubleTap",{touch:c,pageX:b.pageX,pageY:b.pageY,which:1,duration:j/1E3});return}j=e-this.startTime;300<j?l.fire(g,"singleTap",{touch:c,pageX:b.pageX,
pageY:b.pageY,which:1,duration:j/1E3}):this.singleTapTimer=setTimeout(function(){l.fire(g,"singleTap",{touch:c,pageX:b.pageX,pageY:b.pageY,which:1,duration:j/1E3})},300)}}});c.tap=c.doubleTap=c.singleTap=c.tapHold={handle:new h};return h});
KISSY.add("event/dom/touch/swipe",["./handle-map","event/dom/base","./single-touch"],function(f,a){function k(g,c,f){var a=c.changedTouches[0],d=a.pageX-g.startX,p=a.pageY-g.startY,q=Math.abs(d),r=Math.abs(p);if(f){if(g.isVertical&&g.isHorizontal){if(5>Math.max(q,r))return;r>q?g.isHorizontal=0:g.isVertical=0}}else if(g.isVertical&&r<b&&(g.isVertical=0),g.isHorizontal&&q<b)g.isHorizontal=0;if(g.isHorizontal)d=0>d?"left":"right";else if(g.isVertical)d=0>p?"up":"down",q=r;else return!1;l.fire(c.target,
f?e:m,{originalEvent:c.originalEvent,pageX:a.pageX,pageY:a.pageY,which:1,touch:a,direction:d,distance:q,duration:(c.timeStamp-g.startTime)/1E3})}function h(){}var c=a("./handle-map"),l=a("event/dom/base"),i=a("./single-touch"),m="swipe",e="swiping",b=50;f.extend(h,i,{onTouchStart:function(g){if(!1===h.superclass.onTouchStart.apply(this,arguments))return!1;var e=g.touches[0];this.startTime=g.timeStamp;this.isVertical=this.isHorizontal=1;this.startX=e.pageX;this.startY=e.pageY;-1!==g.type.toLowerCase().indexOf("mouse")&&
g.preventDefault()},onTouchMove:function(e){var b=e.changedTouches[0],c=b.pageY-this.startY,b=Math.abs(b.pageX-this.startX),c=Math.abs(c);if(1E3<e.timeStamp-this.startTime)return!1;this.isVertical&&35<b&&(this.isVertical=0);this.isHorizontal&&35<c&&(this.isHorizontal=0);return k(this,e,1)},onTouchEnd:function(e){return!1===this.onTouchMove(e)?!1:k(this,e,0)}});c[m]=c[e]={handle:new h};return h});
KISSY.add("event/dom/touch/multi-touch",["dom"],function(f,a){function k(){}var h=a("dom");k.prototype={constructor:k,requiredTouchCount:2,onTouchStart:function(c){var a=this.requiredTouchCount,f=c.touches.length;f===a?this.start():f>a&&this.end(c)},onTouchEnd:function(c){this.end(c)},start:function(){this.isTracking||(this.isTracking=!0,this.isStarted=!1)},fireEnd:f.noop,getCommonTarget:function(c){var a=c.touches,c=a[0].target,a=a[1].target;if(c===a||h.contains(c,a))return c;for(;;){if(h.contains(a,
c))return a;a=a.parentNode}},end:function(a){this.isTracking&&(this.isTracking=!1,this.isStarted&&(this.isStarted=!1,this.fireEnd(a)))}};return k});
KISSY.add("event/dom/touch/pinch",["./handle-map","event/dom/base","./multi-touch"],function(f,a){function k(){}function h(a){2===a.targetTouches.length&&a.preventDefault()}var c=a("./handle-map"),l=a("event/dom/base"),i=a("./multi-touch");f.extend(k,i,{onTouchMove:function(a){if(this.isTracking){var e=a.touches;if(0<e[0].pageX&&0<e[0].pageY&&0<e[1].pageX&&0<e[1].pageY){var b,g=e[0],c=e[1];b=g.pageX-c.pageX;g=g.pageY-c.pageY;b=Math.sqrt(b*b+g*g);this.lastTouches=e;this.isStarted?l.fire(this.target,
"pinch",f.mix(a,{distance:b,scale:b/this.startDistance})):(this.isStarted=!0,this.startDistance=b,e=this.target=this.getCommonTarget(a),l.fire(e,"pinchStart",f.mix(a,{distance:b,scale:1})))}}},fireEnd:function(a){l.fire(this.target,"pinchEnd",f.mix(a,{touches:this.lastTouches}))}});i=new k;c.pinchStart=c.pinchEnd={handle:i};c=c.pinch={handle:i};f.Features.isTouchEventSupported()&&(c.setup=function(){this.addEventListener("touchmove",h,!1)},c.tearDown=function(){this.removeEventListener("touchmove",
h,!1)});return k});
KISSY.add("event/dom/touch/rotate",["./handle-map","event/dom/base","./multi-touch"],function(f,a){function k(){}function h(a){2===a.targetTouches.length&&a.preventDefault()}var c=a("./handle-map"),l=a("event/dom/base"),i=a("./multi-touch"),m=180/Math.PI;f.extend(k,i,{onTouchMove:function(a){if(this.isTracking){var b=a.touches,c=b[0],h=b[1],i=this.lastAngle,c=Math.atan2(h.pageY-c.pageY,h.pageX-c.pageX)*m;if(void 0!==i){var h=Math.abs(c-i),j=(c+360)%360,d=(c-360)%360;Math.abs(j-i)<h?c=j:Math.abs(d-
i)<h&&(c=d)}this.lastTouches=b;this.lastAngle=c;this.isStarted?l.fire(this.target,"rotate",f.mix(a,{angle:c,rotation:c-this.startAngle})):(this.isStarted=!0,this.startAngle=c,this.target=this.getCommonTarget(a),l.fire(this.target,"rotateStart",f.mix(a,{angle:c,rotation:0})))}},end:function(){this.lastAngle=void 0;k.superclass.end.apply(this,arguments)},fireEnd:function(a){l.fire(this.target,"rotateEnd",f.mix(a,{touches:this.lastTouches}))}});i=new k;c.rotateEnd=c.rotateStart={handle:i};c=c.rotate=
{handle:i};f.Features.isTouchEventSupported()&&(c.setup=function(){this.addEventListener("touchmove",h,!1)},c.tearDown=function(){this.removeEventListener("touchmove",h,!1)});return k});
KISSY.add("event/dom/touch/handle","dom,./handle-map,event/dom/base,./tap,./swipe,./pinch,./rotate".split(","),function(f,a){function k(d){return f.startsWith(d,"touch")}function h(d){return f.startsWith(d,"mouse")}function c(d){return f.startsWith(d,"MSPointer")||f.startsWith(d,"pointer")}function l(d){this.doc=d;this.eventHandle={};this.init();this.touches=[];this.inTouch=0}var i=a("dom"),m=a("./handle-map"),e=a("event/dom/base");a("./tap");a("./swipe");a("./pinch");a("./rotate");var b=f.guid("touch-handle"),
g=f.Features,o,n,j;if(g.isTouchEventSupported())if(f.UA.ios){j="touchend touchcancel";o="touchstart";n="touchmove"}else{j="touchend touchcancel mouseup";o="touchstart mousedown";n="touchmove mousemove"}else if(g.isPointerSupported()){o="pointerdown";n="pointermove";j="pointerup pointercancel"}else if(g.isMsPointerSupported()){o="MSPointerDown";n="MSPointerMove";j="MSPointerUp MSPointerCancel"}else{o="mousedown";n="mousemove";j="mouseup"}l.prototype={constructor:l,lastTouches:[],firstTouch:null,init:function(){var d=
this.doc;e.on(d,o,this.onTouchStart,this);if(!c(n))e.on(d,n,this.onTouchMove,this);e.on(d,j,this.onTouchEnd,this)},addTouch:function(d){d.identifier=d.pointerId;this.touches.push(d)},removeTouch:function(d){for(var a=0,c=d.pointerId,e=this.touches,b=e.length;a<b;a++){d=e[a];if(d.pointerId===c){e.splice(a,1);break}}},updateTouch:function(d){for(var a=0,c,e=d.pointerId,b=this.touches,f=b.length;a<f;a++){c=b[a];c.pointerId===e&&(b[a]=d)}},isPrimaryTouch:function(d){return this.firstTouch===d.identifier},
setPrimaryTouch:function(d){if(this.firstTouch===null)this.firstTouch=d.identifier},removePrimaryTouch:function(d){if(this.isPrimaryTouch(d))this.firstTouch=null},dupMouse:function(d){var a=this.lastTouches,d=d.changedTouches[0];if(this.isPrimaryTouch(d)){var c={x:d.clientX,y:d.clientY};a.push(c);setTimeout(function(){var d=a.indexOf(c);d>-1&&a.splice(d,1)},2500)}},isEventSimulatedFromTouch:function(d){for(var a=this.lastTouches,c=d.clientX,d=d.clientY,e=0,b=a.length,f;e<b&&(f=a[e]);e++){var g=Math.abs(c-
f.x),h=Math.abs(d-f.y);if(g<=25&&h<=25)return true}return 0},normalize:function(d){var a=d.type,e,b;if(e=k(a)){b=a==="touchend"||a==="touchcancel"?d.changedTouches:d.touches;d.isTouch=1}else{if(c(a)&&d.originalEvent.pointerType==="touch")d.isTouch=1;b=this.touches}if(b&&b.length===1){d.which=1;d.pageX=b[0].pageX;d.pageY=b[0].pageY}if(e)return d;a=!a.match(/(up|cancel)$/i);d.touches=a?b:[];d.targetTouches=a?b:[];d.changedTouches=b;return d},onTouchStart:function(d){var a,b;b=d.type;var f=this.eventHandle;
if(k(b)){this.setPrimaryTouch(d.changedTouches[0]);this.dupMouse(d)}else if(h(b)){if(this.isEventSimulatedFromTouch(d))return;this.touches=[d.originalEvent]}else if(c(b)){this.addTouch(d.originalEvent);if(this.touches.length===1)e.on(this.doc,n,this.onTouchMove,this)}else throw Error("unrecognized touch event: "+d.type);for(a in f){b=f[a].handle;b.isActive=1}this.callEventHandle("onTouchStart",d)},onTouchMove:function(d){var a=d.type;if(h(a)){if(this.isEventSimulatedFromTouch(a))return;this.touches=
[d.originalEvent]}else if(c(a))this.updateTouch(d.originalEvent);else if(!k(a))throw Error("unrecognized touch event: "+d.type);this.callEventHandle("onTouchMove",d)},onTouchEnd:function(a){var b=this,g=a.type;if(!h(g)||!b.isEventSimulatedFromTouch(a)){b.callEventHandle("onTouchEnd",a);if(k(g)){b.dupMouse(a);f.makeArray(a.changedTouches).forEach(function(a){b.removePrimaryTouch(a)})}else if(h(g))b.touches=[];else if(c(g)){b.removeTouch(a.originalEvent);b.touches.length||e.detach(b.doc,n,b.onTouchMove,
b)}}},callEventHandle:function(a,b){var c=this.eventHandle,e,f,b=this.normalize(b);if(b.changedTouches.length){for(e in c){f=c[e].handle;if(!f.processed){f.processed=1;if(f.isActive&&f[a]&&f[a](b)===false)f.isActive=0}}for(e in c){f=c[e].handle;f.processed=0}}},addEventHandle:function(a){var b=this.eventHandle,c=m[a].handle;b[a]?b[a].count++:b[a]={count:1,handle:c}},removeEventHandle:function(a){var b=this.eventHandle;if(b[a]){b[a].count--;b[a].count||delete b[a]}},destroy:function(){var a=this.doc;
e.detach(a,o,this.onTouchStart,this);e.detach(a,n,this.onTouchMove,this);e.detach(a,j,this.onTouchEnd,this)}};return{addDocumentHandle:function(a,c){var e=i.getDocument(a),f=i.data(e,b);f||i.data(e,b,f=new l(e));c&&f.addEventHandle(c)},removeDocumentHandle:function(a,c){var e=i.getDocument(a),g=i.data(e,b);if(g){c&&g.removeEventHandle(c);if(f.isEmptyObject(g.eventHandle)){g.destroy();i.removeData(e,b)}}}}});
KISSY.add("event/dom/touch",["event/dom/base","./touch/handle-map","./touch/handle"],function(f,a){function k(a){e.addDocumentHandle(this,a);m[a].setup.apply(this,arguments)}function h(a){e.removeDocumentHandle(this,a);m[a].tearDown.apply(this,arguments)}function c(a){e.addDocumentHandle(this,a)}function l(a){e.removeDocumentHandle(this,a)}var i=a("event/dom/base"),m=a("./touch/handle-map"),e=a("./touch/handle"),b=i.Gesture,g=b.start="KSPointerDown",o=b.move="KSPointerMove",n=b.end="KSPointerUp";
b.tap="tap";b.singleTap="singleTap";b.doubleTap="doubleTap";m[g]={handle:{isActive:1,onTouchStart:function(a){i.fire(a.target,g,a)}}};m[o]={handle:{isActive:1,onTouchMove:function(a){i.fire(a.target,o,a)}}};m[n]={handle:{isActive:1,onTouchEnd:function(a){i.fire(a.target,n,a)}}};var b=i.Special,j,d,p;for(d in m)j={},p=m[d],j.setup=p.setup?k:c,j.tearDown=p.tearDown?h:l,p.add&&(j.add=p.add),p.remove&&(j.remove=p.remove),b[d]=j});
